import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
const path = require('path')
export default defineConfig({
  base: './',
  build: {
    sourcemap: false,
    minify: 'terser',
    chunkSizeWarningLimit: 1500,
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    },
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id
              .toString()
              .split('node_modules/')[1]
              .split('/')[0]
              .toString();
          }
        },
        chunkFileNames: (chunkInfo) => {
          const facadeModuleId = chunkInfo.facadeModuleId
            ? chunkInfo.facadeModuleId.split('/')
            : [];
          const fileName =
            facadeModuleId[facadeModuleId.length - 2] || '[name]';
          return `js/${fileName}/[name].[hash].js`;
        },
        globals: {
          vue: "vue",
      }
      }
    }
  },
  server: {
    host:"0.0.0.0",
    port: 3001, //更改端口
    proxy: {
      "/api": {
        target: "http://localhost:3000/", //代理接口
        changeOrigin: true,
        ws: true,
        rewrite: (path) => path.replace(/^\/api/, "api"),
      },
    }
  },
  define: {
    "process.env": {
      "BASE_API": "/api",
      "VUEX_NAMESPACE":"userinfo"
    }
  },
  resolve: {
    alias: {
      // 配置别名
      '@': path.resolve(__dirname, './src')
    }
  },
  plugins: [
    vue(),
    ]


})
